home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir30 / heaven_1.zip / DDDIST.LSP < prev    next >
Lisp/Scheme  |  1993-08-29  |  5KB  |  176 lines

  1. ;;╔══════════════════════════════════════════════════════════════════════════╗
  2. ;;║Program name:       DDDIST.LSP                                            ║
  3. ;;║Initial Author:     Michael Jenkins                                       ║
  4. ;;║Description:        This is a dialog box for obtaining a distance. It     ║
  5. ;;║                    improves on the DIST commands in three ways. First, it║
  6. ;;║                    checks each point and does not restart if an invalid  ║
  7. ;;║                    point is input. Second, it avoids having to flip to   ║
  8. ;;║                    the text screen to get a distance. Finally, it allows ║
  9. ;;║                    several distances to be obtained without having to    ║
  10. ;;║                    reissue the command.                                  ║
  11. ;;╚══════════════════════════════════════════════════════════════════════════╝
  12.  
  13. ;;; ===================== load-time error checking ============================
  14. ;;;
  15.  
  16. (defun ai_abort (app msg)
  17.    (defun *error* (s)
  18.       (if old_error (setq *error* old_error))
  19.       (princ)
  20.    )
  21.    (if msg
  22.       (alert (strcat " Application error: "
  23.             app
  24.             " \n\n  "
  25.             msg
  26.             "  \n"
  27.          )
  28.       )
  29.    )
  30.    (exit)
  31. )
  32.  
  33. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  34. ;;; and then try to load it.
  35. ;;;
  36. ;;; If it can't be found or it can't be loaded, then abort the
  37. ;;; loading of this file immediately, preserving the (autoload)
  38. ;;; stub function.
  39.  
  40. (cond
  41.    (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  42.  
  43.    (  (not (findfile "ai_utils.lsp"))                     ; find it
  44.       (ai_abort "DDDIST"
  45.          (strcat "Can't locate file AI_UTILS.LSP."
  46.    "\n Check support directory.")))
  47.  
  48.    (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  49.    (ai_abort "DDDIST" "Can't load file AI_UTILS.LSP"))
  50. )
  51.  
  52. (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  53.    (ai_abort "DDDIST" nil)         ; a Nil <msg> supresses
  54. )                                    ; ai_abort's alert box dialog.
  55.  
  56.  
  57. (defun C:DDDIST (/ dddist_pt1 dddist_pt2 id ddlist_again)
  58.  
  59.    (setq *olderror* *error*)
  60.    (defun *error* (msg)
  61.       (princ msg)
  62.       (setq 
  63.          *error* *olderror*
  64.          *olderror* nil
  65.       )
  66.       (princ)
  67.    )
  68.    
  69.    ;go until they pick first point
  70.    (while (=
  71.          (setq
  72.             dddist_pt1
  73.             (getpoint "\nFirst point: ")
  74.          )
  75.          nil
  76.       )
  77.       (prompt "\nInvalid point.")
  78.    )
  79.  
  80.    ;get second point with rubberband from first
  81.    (while (=
  82.          (setq
  83.             dddist_pt2
  84.             (getpoint dddist_pt1 "\nSecond point: ")
  85.          )
  86.          nil
  87.       )
  88.       (prompt "\nInvalid point.")
  89.    )
  90.  
  91.    ;set up the dialog identification
  92.    (setq id (load_dialog "dddist"))
  93.  
  94.    ;open dialog and store location as a global
  95.    (new_dialog "dddist" id "" #dddist_loc)
  96.  
  97.    ;set up the 2-D option
  98.    (if (/= #dddist_2d "1")
  99.       (set_tile "distance"
  100.          (strcat "         Distance: "
  101.             (rtos (distance dddist_pt1 dddist_pt2))
  102.          )
  103.       )
  104.       (set_tile "distance"
  105.          (strcat "    Distance (2D): "
  106.             (rtos (distance 
  107.                   (list (car dddist_pt1) (cadr dddist_pt2) 0)
  108.                   (list (car dddist_pt2) (cadr dddist_pt2) 0)
  109.                )
  110.             )
  111.          )
  112.       )
  113.    )
  114.  
  115.    ;tile setup
  116.    (set_tile "angle"
  117.       (strcat "Angle in XY Plane: "
  118.          (angtos (angle
  119.                (list (car dddist_pt1) (cadr dddist_pt1) 0)
  120.                (list (car dddist_pt2) (cadr dddist_pt2) 0)
  121.             )
  122.          )
  123.       )
  124.    )
  125.    (set_tile "deltax"
  126.       (strcat "          Delta X: "
  127.          (rtos (distance
  128.                (list (car dddist_pt1) 0 0)
  129.                (list (car dddist_pt2) 0 0)
  130.             )
  131.          )
  132.       )
  133.    )
  134.    (set_tile "deltay"
  135.       (strcat "          Delta Y: "
  136.          (rtos (distance
  137.                (list 0 (cadr dddist_pt1) 0)
  138.                (list 0 (cadr dddist_pt2) 0)
  139.             )
  140.          )
  141.       )
  142.    )
  143.    (set_tile "deltaz"
  144.       (strcat "          Delta Z: "
  145.          (rtos (distance
  146.                (list 0 0 (caddr dddist_pt1))
  147.                (list 0 0 (caddr dddist_pt2))
  148.             )
  149.          )
  150.       )
  151.    )
  152.  
  153.    ;reset to nil for check later
  154.    (setq dddist_again nil)
  155.  
  156.    ;highlight the 2D option if present
  157.    (if (= #dddist_2D "1")
  158.       (set_tile "2d" "1")
  159.    )
  160.  
  161.    ;set up callbacks
  162.    (action_tile "accept"  "(setq #dddist_loc (done_dialog))")
  163.    (action_tile "2d"      "(setq #dddist_2d $value)")
  164.    (action_tile "again"   "(setq dddist_again T #dddist_loc (done_dialog))")
  165.  
  166.    (start_dialog)
  167.    (unload_dialog id)
  168.  
  169.    ;do it again if necessary
  170.    (if dddist_again(C:DDDIST))
  171.    (prin1)
  172. ) ;defun dddist  
  173. ;;================================ The End ===================================
  174. (princ "DDDIST Loaded.")                   
  175. (princ)
  176.